import { ref } from 'vue'
import { defineStore } from 'pinia'
import { loginAPI } from "@/apis/login"

export const useUserStore = defineStore('user', () => {
  const userInfo = ref({})
  // 异步获取用户信息
  const getUserInfo = async({account, password}) => {
    const res = await loginAPI({account, password})
    userInfo.value = res.result
  }
   // 退出时清除用户信息
   const clearUserInfo = () => {
    userInfo.value = {}
  }
  return { userInfo,  getUserInfo, clearUserInfo}
},{
  persist: true,
})
